<?php

namespace App\Kuafu\CouponPackage\Validate;

use App\Kuafu\Activity\Enum\ActivityEnum;
use App\Kuafu\Coupon\Model\CouponModel;
use App\Kuafu\CouponPackage\Enum\CouponPackageEnum;
use App\Kuafu\Base\Validate\BaseValidate;
use Illuminate\Support\Facades\Validator;

class CouponPackageShopMappingValidate extends BaseValidate
{

    public static function getRules()
    {
        return [
            'shopInfo' => [
                'exclude_unless:shopType,' . CouponPackageEnum::SHOP_TYPE_SELECTION,
                'required',
                'array',
                function ($attribute, $value, $fail) {
                    if (empty($value) || empty(array_filter($value))) {
                        $fail('The ' . $attribute . ' is invalid.');
                    }
                }
            ],
        ];
    }


    /**
     * @param array $requestParams
     * @return array
     */
    public static function insertValidate(array $requestParams): array
    {
        return [
            self::getRequestParams($requestParams,
                array_keys(self::getRules()), function ($params) use($requestParams) {
                    if ($requestParams['shopType'] != CouponPackageEnum::SHOP_TYPE_SELECTION) {
                        $params['shopInfo'] = [];
                    }
                    return $params;
                }),
            self::validateCheck($requestParams, self::getRules(), [])
        ];
    }

}
